import 'package:flutter/material.dart';
import 'router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
      onGenerateRoute: onGenerateRoute,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // Scaffold: Flutter应用的脚手架，用来搭建Flutter项目的基本布局结构。
    return Scaffold(
      // AppBar: 显示在界面顶部的一个AppBar，也就是Android中的ActionBar, Toolbar
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      // Drawer: 成为抽屉菜单，一般隐藏起来，点击后以侧滑的方式展示出来
      drawer: Drawer(
        // Column 是 Flex 的⼦集，默认主轴⽅向是列（direction: Axis.vertical）
        // 常用属性
        //   mainAxisAlignment：MainAxisAlignment 主轴对齐方式
        //   crossAxisAlignment：CrossAxisAlignment 交叉抽对齐方式
        //   children 声明多个子组件
        child: Column(
          children: <Widget>[
            // Row 是 Flex 的子集，默认主轴方向是列（direction: Axis.horizontal）
            // 常用属性
            //   mainAxisAlignment：MainAxisAlignment 主轴对齐方式
            //   crossAxisAlignment：CrossAxisAlignment 交叉抽对齐方式
            //   children 声明多个子组件
            Row(
             children: const <Widget>[
               // Expanded 可以动态调整子组件沿主轴的尺寸，比如填充剩余空间，比如设置尺寸比例。它常常和 Row 或 Column 组合起来使用。
               // 常用属性
               //     child 声明多个子组件
               //     flex 声明所占比例
               Expanded(
                 child: UserAccountsDrawerHeader(
                     accountEmail: Text("My Email"),
                     accountName: Text("My Name"),
                 )
               )
            ],
            ),
            ListTile(
              leading: const Icon(Icons.credit_card),
              title: const Text("Button"),
              onTap: () {Navigator.pushNamed(context, "ButtonPage");},
            ),
            const Divider(), // 分割线
            ListTile(
              leading: const Icon(Icons.credit_card),
              title: const Text("Card"),
              onTap: () {Navigator.pushNamed(context, "CardPage");},
            ),
            const Divider(),
            ListTile(
              leading: const Icon(Icons.list),
              title: const Text("List"),
              onTap: () {Navigator.pushNamed(context, "ListPage");},
            ),
            const Divider(),
            ListTile(
              leading: const Icon(Icons.task_alt),
              title: const Text("Switch"),
              onTap: () {Navigator.pushNamed(context, "SwitchPage");},
            ),
            const Divider(),
            ListTile(
              leading: const Icon(Icons.article),
              title: const Text("Text"),
              onTap: () {Navigator.pushNamed(context, "TextPage");},
            ),
          ],
        ),
      ),
      // Body: 当前界面的主体Widget
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            // Text
            // 常用属性
            // TextDirection
            //   TextDirection.ltr： 从左向右的
            //   TextDirection.rtl： 从右向左的
            // TextStyle
            //   color： 字体颜色
            //   fontSize： 字体大小
            //   fontWeight： 字体粗细
            //   fontStyle： normal 或者 italic
            //   fontFamily： 字体
            //   letterSpacing： 字母间隙
            //   wordSpacing： 单词间隙
            // TextAlign
            //   center： 文本居中
            //   left： 左对齐
            //   right： 右对齐
            //   start： 开始处对齐，类似于左对齐
            //   end： 结尾处对齐
            // MaxLines 设置最多显示的行数
            // Overflow
            //   clip： 直接切断，剩下的文字就没有了。
            //   ellipsis： 在后边显示省略号。
            //   fade： 溢出的部分会进行一个渐变消失的效果，当然是上下的渐变，不是左右的
            const Text(
              'Hello Word.',
              textDirection: TextDirection.ltr,
            ),
            // Wrap 如果子组件超出屏幕范围，则会报溢出错误。而 Wrap 可以有效解决内容溢出
            // 常用属性
            //     spacing：主轴方向子组件的间距
            //     alignment: 主轴方向的对齐方式
            //     runSpacing：纵轴方向子组件的间距
            //     runAlignment：纵轴方向的对齐方式
            Wrap(
              spacing: 8.0,
              runSpacing: 4.0,
              alignment: WrapAlignment.spaceAround,
              children: [
                Chip(
                  avatar: CircleAvatar(
                    backgroundColor: Colors.blue,
                    child: Text('蜀')
                  ),
                  label: Text("刘备")
                ),
                Chip(
                    avatar: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text('蜀')
                    ),
                    label: Text("关羽")
                ),
                Chip(
                    avatar: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text('蜀')
                    ),
                    label: Text("张飞")
                ),
                Chip(
                    avatar: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text('蜀')
                    ),
                    label: Text("赵云")
                ),
                Chip(
                    avatar: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text('蜀')
                    ),
                    label: Text("马超")
                ),
                Chip(
                    avatar: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text('蜀')
                    ),
                    label: Text("诸葛亮")
                )
              ],
            )
          ],
        ),
      ),
      // FloatingActionButton 简称FAB，可以实现浮动按钮
      // 常用属性：
      // child: 子视图，一般为 Icon，不推荐使用文字
      // tooltip: 被长按时显示，也是无障碍功能
      // backgroundColor： 背景颜色
      // elevation: 未点击的时候的阴影
      // hignlightElevation: 点击时阴影值，默认 12.0
      // onPressed: 点击事件回调
      // shape: 可以定义 FAB 的形状等
      // mini: 是否是 mini 类型默认 false
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        // Icon: 用来声明图标，Icons 是Flutter 中的图标组件 (在线预览：https://material.io/resources/icons)
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
      // BottomNavigationBar 显示在页面底部的导航栏
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: "设置"),
        ],
      ),
    );
  }
}
